package com.sys.controller;

import com.sys.common.constant.Constant;
import com.sys.common.util.ResponseDateUtil;
import com.sys.common.util.ResultBuilder;
import com.sys.pojo.User;
import com.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@Api("登录")
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    @ApiOperation("登录")
    public ResponseDateUtil login(@RequestBody User user) {
        Map map = userService.login(user);
        if (map != null) {
            return ResultBuilder.success(map);
        } else {
            return ResultBuilder.errorInfo(Constant.LOGINERROR);
        }
    }

}